<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }

    .nav {
        width: 100%;
        height: 70px;
        background-color: pink;
    }

    .nav>a {
        line-height: 70px;
        margin-left: 50px;
        text-decoration: none;
        font-size: 20px;
    }

    .box {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 300px;
        height: 300px;
        border: 1px solid #000000;

    }

    .box>h2 {
        height: 50px;
        background-color: orange;
        line-height: 50px;
        font-size: 20px;
        cursor: move;
    }

    .box>h2>span {
        float: right;
        margin-right: 10px;
    }
</style>

<body>
    <div class="nav">
        <a href="#">注册信息</a>
    </div>
    <div class="box">
        <h2>注册信息(可以拖拽)
            <span>关闭</span>
        </h2>
    </div>
</body>
<script>
    window.onload = function () {
        var box = document.querySelector('.box')
        var dian = document.querySelector('h2')

        dian.onmousedown = function (event) {
            event = event || window.event
            var initleft = event.clientX
            var inittop = event.clientY
            var x = box.offsetLeft
            var y = box.offsetTop

            document.onmousemove = function (event) {
                event = event || window.event
                var moveX = event.clientX - initleft + x
                var moveY = event.clientY - inittop + y


                box.style.left = moveX + 'px'
                box.style.top = moveY + 'px'

                window.getSelection() ? window.getSelection().removeAllRanges() : document.selection.empty();
            }

            document.onmouseup = function () {
                document.onmousemove = ''
            }
        }
    }
</script>

</html>